package com.aabte.springcloudlearn.feigncustomerdemo.fallback;

import com.aabte.springcloudlearn.feigncustomerdemo.service.RetryCustomerFeignService;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * {@link RetryCustomerFeignService} 对应降级工厂，实现针对不同的异步返加不同的降级处理对象
 *
 * @author Daniel
 */
@Slf4j
@Component
public class RetryCustomerFeignServiceFallbackFactory implements FallbackFactory<RetryCustomerFeignService> {
    @Override
    public RetryCustomerFeignService create(Throwable throwable) {
        // 此处可实现根据异常信息返回不同的降级对象
        return new RetryCustomerFeignService() {
            @Override
            public String feignRetry() {
                log.warn("Start fallback by RetryCustomerFeignServiceFallbackFactory.");
                return "Fallback by RetryCustomerFeignServiceFallbackFactory!";
            }
        };
    }
}
